/**
 * Copyright © 2016-2021 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.iot.entity.dto;

import com.example.iot.entity.RuleNode;
import com.example.iot.entity.id.RuleChainId;
import com.example.iot.entity.id.RuleNodeId;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by igor on 3/13/18.
 */
@Data
public class RuleChainMetaData {

    /**
     * 规则链id
     */
    private RuleChainId ruleChainId;

    /**
     * 首规则节点id
     */
    private Integer firstNodeIndex;

    /**
     * 规则节点集合
     */
    private List<RuleNode> nodes;

    /**
     * 节点连接信息集合
     */
    private List<NodeConnectionInfo> connections;

    /**
     * 添加规则节点连接信息
     * @param fromId 发出节点id
     * @param toId 接收节点id
     * @param type 连接结果
     */
    public void addConnectionInfo(RuleNodeId fromId, int fromIndex, RuleNodeId toId, int toIndex, String type) {
        NodeConnectionInfo connectionInfo = new NodeConnectionInfo();
        connectionInfo.setFromId(fromId);
        connectionInfo.setFromIndex(fromIndex);
        connectionInfo.setToId(toId);
        connectionInfo.setToIndex(toIndex);
        connectionInfo.setType(type);
        if (connections == null) {
            connections = new ArrayList<>();
        }
        connections.add(connectionInfo);
    }
}
